﻿using Bing.Helpers;

namespace Bing.Logging.Tests;

/// <summary>
/// 日志上下文访问器
/// </summary>
public class LogContextAccessor : ILogContextAccessor
{
    /// <summary>
    /// 日志上下文键名
    /// </summary>
    public const string LogContextKey = "Bing.Logging.LogContext";

    /// <summary>
    /// 日志上下文
    /// </summary>
    public LogContext Context
    {
        get
        {
            var slot = System.Threading.Thread.GetNamedDataSlot(LogContextKey);
            return Conv.To<LogContext>(System.Threading.Thread.GetData(slot));

        }
        set
        {
            var slot = System.Threading.Thread.GetNamedDataSlot(LogContextKey);
            System.Threading.Thread.SetData(slot, value);
        }
    }
}